package com.grass.p019lv.activity;

import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.APPLink;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AdInfoBean;
import com.androidx.p013lv.base.bean.ContentBean;
import com.androidx.p013lv.base.bean.DownLoadVideoNumBean;
import com.androidx.p013lv.base.bean.RelateVideoBean;
import com.androidx.p013lv.base.bean.UserAccount;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.bean.event.CanWatchVipEvent;
import com.androidx.p013lv.base.bean.event.LikeVideoEvent;
import com.androidx.p013lv.base.dialog.DialogRatingBar;
import com.androidx.p013lv.base.event.M3u8Event;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.model.M3u8Model;
import com.androidx.p013lv.base.model.VideoPlayerModel;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.service.AdClickService;
import com.androidx.p013lv.base.utils.AdUtils;
import com.androidx.p013lv.base.utils.LogUtils;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.CircleImageView;
import com.androidx.p013lv.player.view.VideoPlayer;
import com.google.android.exoplayer2.SeekParameters;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.grass.p019lv.adapter.LikeVideoAdapter;
import com.grass.p019lv.adapter.RelatedWorksAdapter;
import com.grass.p019lv.bean.DownloadVideoBean;
import com.grass.p019lv.databinding.ActivityVideoPlayLayoutBinding;
import com.grass.p019lv.dialog.DownLoadVideoDialog;
import com.grass.p019lv.service.DownloadVideoService;
import com.gyf.immersionbar.ImmersionBar;
import com.p020lv.downloadvideo.M3U8Downloader;
import com.p020lv.downloadvideo.OnM3U8DownloadListener;
import com.p020lv.downloadvideo.bean.M3U8Task;
import com.p020lv.downloadvideo.utils.DataCacheUtils;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import java.util.ArrayList;
import java.util.List;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import p000a.shuyu.p005a.GSYVideoManager;
import p000a.shuyu.p005a.builder.GSYVideoOptionBuilder;
import p000a.shuyu.p005a.listener.GSYSampleCallBack;
import p000a.shuyu.p005a.listener.GSYVideoProgressListener;
import p000a.shuyu.p005a.listener.LockClickListener;
import p000a.shuyu.p005a.utils.OrientationUtils;
import p000a.shuyu.p005a.video.StandardGSYVideoPlayer;
import p023io.reactivex.Observable;
import p023io.reactivex.ObservableEmitter;
import p023io.reactivex.ObservableOnSubscribe;
import p023io.reactivex.android.schedulers.AndroidSchedulers;
import p023io.reactivex.disposables.CompositeDisposable;
import p023io.reactivex.functions.Consumer;
import p023io.reactivex.schedulers.Schedulers;
import p031tv.danmaku.ijk.media.exo2.Exo2PlayerManager;

/* renamed from: com.grass.lv.activity.VideoPlayActivity */
public class VideoPlayActivity extends BaseActivity<ActivityVideoPlayLayoutBinding> implements DialogRatingBar.OnRatingBarCommitListener, GSYVideoProgressListener {
    APPLink appLink;
    private CompositeDisposable compositeDisposable;
    private ArrayList<DownloadVideoBean> downLoadTask = new ArrayList<>();
    private boolean isFirst = true;
    private boolean isReport = false;
    private LikeVideoAdapter likeAdapter;
    private ItemClickListener likeItemClickListener = new ItemClickListener() {
        /* class com.grass.p019lv.activity.VideoPlayActivity.C29422 */

        @Override // com.androidx.p013lv.base.listener.ItemClickListener
        public void onItemClick(View view, int i) {
            VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
            videoPlayActivity.videoId = ((RelateVideoBean.DataBean) videoPlayActivity.likeAdapter.getDataInPosition(i)).getVideoId();
            VideoPlayActivity.this.itemOnClick();
        }
    };
    private M3u8Model m3u8Model;
    private Gson mGson = new Gson();
    private VideoPlayerModel model;
    private OnM3U8DownloadListener onM3U8DownloadListener = new OnM3U8DownloadListener() {
        /* class com.grass.p019lv.activity.VideoPlayActivity.C293918 */

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadItem(M3U8Task m3U8Task, long j, int i, int i2) {
            super.onDownloadItem(m3U8Task, j, i, i2);
        }

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadSuccess(M3U8Task m3U8Task) {
            super.onDownloadSuccess(m3U8Task);
            VideoPlayActivity.this.updateText(m3U8Task);
        }

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadPending(M3U8Task m3U8Task) {
            super.onDownloadPending(m3U8Task);
            VideoPlayActivity.this.updateText(m3U8Task);
        }

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadPause(M3U8Task m3U8Task) {
            super.onDownloadPause(m3U8Task);
            VideoPlayActivity.this.updateText(m3U8Task);
        }

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadProgress(M3U8Task m3U8Task) {
            super.onDownloadProgress(m3U8Task);
            VideoPlayActivity.this.updateText(m3U8Task);
        }

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadPrepare(M3U8Task m3U8Task) {
            super.onDownloadPrepare(m3U8Task);
            VideoPlayActivity.this.updateText(m3U8Task);
        }

        @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
        public void onDownloadError(final M3U8Task m3U8Task, Throwable th) {
            super.onDownloadError(m3U8Task, th);
            if (NetUtil.isNetworkAvailable()) {
                new Handler().postDelayed(new Runnable() {
                    /* class com.grass.p019lv.activity.VideoPlayActivity.C293918.RunnableC29401 */

                    public void run() {
                        M3U8Downloader.getInstance().download(m3U8Task.getUrl());
                    }
                }, 5000);
            }
        }
    };
    private OrientationUtils orientationUtils;
    private DialogRatingBar ratingBar;
    private int status;
    private UserAccount userAccount;
    private UserInfo userInfo;
    private VideoBean videoBean;
    public int videoId;
    private String videoUrl;
    private RelatedWorksAdapter worksAdapter;
    private ItemClickListener worksItemClickListener = new ItemClickListener() {
        /* class com.grass.p019lv.activity.VideoPlayActivity.C29281 */

        @Override // com.androidx.p013lv.base.listener.ItemClickListener
        public void onItemClick(View view, int i) {
            VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
            videoPlayActivity.videoId = ((RelateVideoBean.DataBean) videoPlayActivity.worksAdapter.getDataInPosition(i)).getVideoId();
            VideoPlayActivity.this.itemOnClick();
        }
    };

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_video_play_layout;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void itemOnClick() {
        if (!isOnClick()) {
            VideoBean videoBean2 = this.videoBean;
            if (videoBean2 != null && videoBean2.isCanWatch()) {
                this.model.insertHistory(this.videoBean, ((ActivityVideoPlayLayoutBinding) this.binding).player.getProgress());
            }
            this.status = 0;
            ((ActivityVideoPlayLayoutBinding) this.binding).setStatus(Integer.valueOf(this.status));
            this.isReport = false;
            this.videoBean = null;
            this.videoUrl = UrlManager.getInsatance().playBaseFull2(this.videoId);
            this.model.getVideoById(this.videoId, this);
            this.model.relatedVideo(this.videoId);
            this.model.guessLikeVideo(this.videoId);
            ((ActivityVideoPlayLayoutBinding) this.binding).scrollView.scrollTo(0, 0);
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityVideoPlayLayoutBinding) this.binding).toolbar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        getWindow().addFlags(1024);
        EventBus.getDefault().register(this);
        this.model = (VideoPlayerModel) new ViewModelProvider(this).get(VideoPlayerModel.class);
        this.m3u8Model = (M3u8Model) new ViewModelProvider(this).get(M3u8Model.class);
        this.userInfo = SpUtils.getInstance().getUserInfo();
        ((ActivityVideoPlayLayoutBinding) this.binding).setUserInfo(this.userInfo);
        this.status = 0;
        ((ActivityVideoPlayLayoutBinding) this.binding).setStatus(Integer.valueOf(this.status));
        ((ActivityVideoPlayLayoutBinding) this.binding).setRelateStatus(0);
        ((ActivityVideoPlayLayoutBinding) this.binding).setLikeStatus(0);
        ((ActivityVideoPlayLayoutBinding) this.binding).setClick(new OnClick());
        ((ActivityVideoPlayLayoutBinding) this.binding).setHeight(Integer.valueOf((UiUtils.getWindowWidth() * 9) / 16));
        this.userAccount = SpUtils.getInstance().getUserAccount();
        RelatedWorksAdapter relatedWorksAdapter = new RelatedWorksAdapter();
        this.worksAdapter = relatedWorksAdapter;
        relatedWorksAdapter.setItemListener(this.worksItemClickListener);
        LikeVideoAdapter likeVideoAdapter = new LikeVideoAdapter();
        this.likeAdapter = likeVideoAdapter;
        likeVideoAdapter.setItemListener(this.likeItemClickListener);
        ((ActivityVideoPlayLayoutBinding) this.binding).worksRecycler.setLayoutManager(new LinearLayoutManager(this, 0, false));
        ((ActivityVideoPlayLayoutBinding) this.binding).worksRecycler.setAdapter(this.worksAdapter);
        ((ActivityVideoPlayLayoutBinding) this.binding).likeRecycler.setLayoutManager(new LinearLayoutManager(this));
        ((ActivityVideoPlayLayoutBinding) this.binding).likeRecycler.setAdapter(this.likeAdapter);
        DialogRatingBar dialogRatingBar = new DialogRatingBar(this);
        this.ratingBar = dialogRatingBar;
        dialogRatingBar.setOnRatingBarListener(this);
        initPlayer();
        this.videoUrl = UrlManager.getInsatance().playBaseFull2(this.videoId);
        ((ActivityVideoPlayLayoutBinding) this.binding).player.startPlayLogic();
        setAd();
        M3U8Downloader.getInstance().setOnM3U8DownloadListener2(this.onM3U8DownloadListener);
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initData() {
        this.model.dataVideo().observe(this, new Observer<BaseRes<VideoBean>>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29433 */

            public void onChanged(BaseRes<VideoBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    VideoPlayActivity.this.videoBean = baseRes.getData();
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setVideoBean(VideoPlayActivity.this.videoBean);
                    if (VideoPlayActivity.this.videoBean.getTagTitles() != null && VideoPlayActivity.this.videoBean.getTagTitles().size() > 0) {
                        VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
                        videoPlayActivity.setDynamicTag(videoPlayActivity.videoBean.getTagTitles());
                    }
                    if (!TextUtils.isEmpty(VideoPlayActivity.this.videoBean.getPlayPath())) {
                        VideoPlayActivity.this.playerSubsequentProcessing();
                        return;
                    }
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).player.onVideoPause();
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).player.release();
                    VideoPlayActivity videoPlayActivity2 = VideoPlayActivity.this;
                    videoPlayActivity2.status = videoPlayActivity2.videoBean.getReasonType();
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setStatus(Integer.valueOf(VideoPlayActivity.this.status));
                    return;
                }
                ToastUtils.getInstance().showWrong(baseRes.getMsg());
            }
        });
        this.model.dataRelate().observe(this, new Observer<BaseRes<RelateVideoBean>>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29444 */

            public void onChanged(BaseRes<RelateVideoBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    RelateVideoBean data = baseRes.getData();
                    if (data == null || data.getData() == null || data.getData().size() == 0) {
                        ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setRelateStatus(0);
                        return;
                    }
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setRelateStatus(1);
                    VideoPlayActivity.this.worksAdapter.setDomain(data.getDomain());
                    VideoPlayActivity.this.worksAdapter.setData(data.getData());
                    return;
                }
                ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setRelateStatus(0);
            }
        });
        this.model.dataGuessLike().observe(this, new Observer<BaseRes<RelateVideoBean>>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29455 */

            public void onChanged(BaseRes<RelateVideoBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    RelateVideoBean data = baseRes.getData();
                    if (data == null || data.getData() == null || data.getData().size() == 0) {
                        ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setLikeStatus(0);
                        return;
                    }
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setLikeStatus(1);
                    VideoPlayActivity.this.likeAdapter.setDomain(data.getDomain());
                    VideoPlayActivity.this.likeAdapter.setData(data.getData());
                    return;
                }
                ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setLikeStatus(0);
            }
        });
        this.model.dataScore().observe(this, new Observer<BaseRes>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29466 */

            public void onChanged(BaseRes baseRes) {
                if (baseRes.getCode() == 200) {
                    VideoPlayActivity.this.videoBean.setFakeScoreNum(VideoPlayActivity.this.videoBean.getFakeScoreNum() + 1);
                    ToastUtils.getInstance().showCorrect("評分成功");
                    VideoPlayActivity.this.videoBean.setScored(true);
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setVideoBean(VideoPlayActivity.this.videoBean);
                    return;
                }
                ToastUtils.getInstance().showWrong(baseRes.getMsg());
            }
        });
        this.model.dataBuyVideo().observe(this, new Observer<BaseRes<Integer>>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29477 */

            public void onChanged(BaseRes<Integer> baseRes) {
                if (baseRes.getCode() == 200) {
                    VideoPlayActivity.this.status = 0;
                    ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setStatus(Integer.valueOf(VideoPlayActivity.this.status));
                    VideoPlayActivity.this.videoBean.setCanWatch(true);
                    VideoPlayActivity.this.videoUrl = UrlManager.getInsatance().playBaseFull2(VideoPlayActivity.this.videoId);
                    VideoPlayActivity.this.model.getVideoById(VideoPlayActivity.this.videoId, VideoPlayActivity.this);
                    if (baseRes.getData().intValue() == 1) {
                        ToastUtils.getInstance().showCorrect("購買成功");
                        VideoPlayActivity.this.userAccount.setGold(VideoPlayActivity.this.userAccount.getGold() - VideoPlayActivity.this.videoBean.getPrice());
                        SpUtils.getInstance().setUserAccount(VideoPlayActivity.this.userAccount);
                        return;
                    }
                    ToastUtils.getInstance().showCorrect("租賃成功");
                    VideoPlayActivity.this.userAccount.setGold(VideoPlayActivity.this.userAccount.getGold() - VideoPlayActivity.this.videoBean.getLeasePrice());
                    SpUtils.getInstance().setUserAccount(VideoPlayActivity.this.userAccount);
                    return;
                }
                ToastUtils.getInstance().showWrong(baseRes.getMsg());
            }
        });
        this.model.getVideoById(this.videoId, this);
        this.model.relatedVideo(this.videoId);
        this.model.guessLikeVideo(this.videoId);
        this.model.getDownLoadVideoData().observe(this, new Observer<BaseRes<DownLoadVideoNumBean>>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29488 */

            public void onChanged(BaseRes<DownLoadVideoNumBean> baseRes) {
                if (baseRes.getCode() == 200 && baseRes.getData() != null) {
                    VideoPlayActivity.this.downLoad(baseRes.getData().getDownloadNum());
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setDynamicTag(final List<VideoBean.TagTitles> list) {
        ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.flowType.setAdapter(new TagAdapter<VideoBean.TagTitles>(list) {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C29499 */

            public View getView(FlowLayout flowLayout, final int i, VideoBean.TagTitles tagTitles) {
                RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(flowLayout.getContext()).inflate(R.layout.video_play_tag_flow, (ViewGroup) flowLayout, false);
                TextView textView = (TextView) relativeLayout.findViewById(R.id.tv_label);
                textView.setText("#" + ((VideoBean.TagTitles) list.get(i)).getTagsTitle());
                textView.setOnClickListener(new View.OnClickListener() {
                    /* class com.grass.p019lv.activity.VideoPlayActivity.C29499.View$OnClickListenerC29501 */

                    public void onClick(View view) {
                        if (!VideoPlayActivity.this.isOnClick()) {
                            Intent intent = new Intent(VideoPlayActivity.this, SearchLabelActivity.class);
                            intent.putExtra("data", ((VideoBean.TagTitles) list.get(i)).getTagsTitle());
                            VideoPlayActivity.this.startActivity(intent);
                        }
                    }
                });
                return relativeLayout;
            }
        });
    }

    /* access modifiers changed from: protected */
    @Override // androidx.fragment.app.FragmentActivity
    public void onNewIntent(Intent intent) {
        setIntent(intent);
        super.onNewIntent(intent);
        ARouter.getInstance().inject(this);
        this.videoBean = null;
        this.isReport = false;
        this.status = 0;
        ((ActivityVideoPlayLayoutBinding) this.binding).setStatus(Integer.valueOf(this.status));
        ((ActivityVideoPlayLayoutBinding) this.binding).setRelateStatus(0);
        ((ActivityVideoPlayLayoutBinding) this.binding).setLikeStatus(0);
        this.model.getVideoById(this.videoId, this);
        this.model.relatedVideo(this.videoId);
        this.model.guessLikeVideo(this.videoId);
    }

    private void initPlayer() {
        OrientationUtils orientationUtils2 = new OrientationUtils(this, ((ActivityVideoPlayLayoutBinding) this.binding).player);
        this.orientationUtils = orientationUtils2;
        orientationUtils2.setEnable(false);
        new GSYVideoOptionBuilder().setRotateViewAuto(false).setLockLand(false).setAutoFullWithSize(false).setShowFullAnimation(false).setNeedLockFull(true).setVideoAllCallBack(new GSYSampleCallBack() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C293011 */

            @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
            public void onPrepared(String str, Object... objArr) {
                super.onPrepared(str, objArr);
                VideoPlayActivity.this.orientationUtils.setEnable(true);
                try {
                    if (((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).player.getGSYVideoManager().getPlayer() instanceof Exo2PlayerManager) {
                        ((Exo2PlayerManager) ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).player.getGSYVideoManager().getPlayer()).setSeekParameter(SeekParameters.NEXT_SYNC);
                    }
                } catch (Exception unused) {
                    LogUtils.m63e("---->", "设置 seek 的临近帧");
                }
            }

            @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
            public void onEnterFullscreen(String str, Object... objArr) {
                super.onEnterFullscreen(str, objArr);
            }

            @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
            public void onAutoComplete(String str, Object... objArr) {
                super.onAutoComplete(str, objArr);
                if (VideoPlayActivity.this.videoBean != null && !VideoPlayActivity.this.videoBean.isCanWatch()) {
                    VideoPlayActivity.this.canWatchFollowUp();
                }
            }

            @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
            public void onClickStartError(String str, Object... objArr) {
                super.onClickStartError(str, objArr);
            }

            @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
            public void onQuitFullscreen(String str, Object... objArr) {
                super.onQuitFullscreen(str, objArr);
                if (VideoPlayActivity.this.orientationUtils != null) {
                    VideoPlayActivity.this.orientationUtils.backToProtVideo();
                }
            }
        }).setLockClickListener(new LockClickListener() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C292910 */

            @Override // p000a.shuyu.p005a.listener.LockClickListener
            public void onClick(View view, boolean z) {
                if (VideoPlayActivity.this.orientationUtils != null) {
                    VideoPlayActivity.this.orientationUtils.setEnable(!z);
                }
            }
        }).setGSYVideoProgressListener(this).build((StandardGSYVideoPlayer) ((ActivityVideoPlayLayoutBinding) this.binding).player);
        ((ActivityVideoPlayLayoutBinding) this.binding).player.getBackButton().setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.View$OnClickListenerC293112 */

            public void onClick(View view) {
                VideoPlayActivity.this.onBackPressed();
            }
        });
        ((ActivityVideoPlayLayoutBinding) this.binding).player.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.View$OnClickListenerC293213 */

            public void onClick(View view) {
                VideoPlayActivity.this.orientationUtils.resolveByClick();
                ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).player.startWindowFullscreen(VideoPlayActivity.this, true, true);
            }
        });
    }

    @Override // com.androidx.p013lv.base.dialog.DialogRatingBar.OnRatingBarCommitListener
    public void onRatingBarCommit(float f) {
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null) {
            this.model.userVideoScore((double) f, videoBean2.getVideoId());
        }
    }

    public static void loadContentHead(CircleImageView circleImageView, VideoBean videoBean2) {
        if (videoBean2 == null || videoBean2.getContentList() == null || videoBean2.getContentList().size() <= 0) {
            GlideUtils.loadPicHeadDefault(circleImageView);
            return;
        }
        GlideUtils.loadPicHead(SpUtils.getInstance().getString("domain") + videoBean2.getContentList().get(0).getHeadImg(), circleImageView);
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        ((ActivityVideoPlayLayoutBinding) this.binding).player.onConfigurationChanged(this, configuration, this.orientationUtils, true, true);
    }

    @Override // androidx.activity.ComponentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onBackPressed() {
        OrientationUtils orientationUtils2 = this.orientationUtils;
        if (orientationUtils2 != null) {
            orientationUtils2.backToProtVideo();
        }
        if (!GSYVideoManager.backFromWindowFull(this)) {
            super.onBackPressed();
        }
    }

    @Override // p000a.shuyu.p005a.listener.GSYVideoProgressListener
    public void onProgress(int i, int i2, int i3, int i4) {
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null) {
            if (!videoBean2.isCanWatch() && i3 >= 60000) {
                canWatchFollowUp();
            }
            if (this.videoBean.isCanWatch() && !this.isReport && i3 >= 5000) {
                this.isReport = true;
                addVideoWatchTimes(i3 / 1000);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void canWatchFollowUp() {
        OrientationUtils orientationUtils2;
        if (((ActivityVideoPlayLayoutBinding) this.binding).player.isIfCurrentIsFullscreen() && (orientationUtils2 = this.orientationUtils) != null) {
            orientationUtils2.backToProtVideo();
        }
        OrientationUtils orientationUtils3 = this.orientationUtils;
        if (orientationUtils3 != null) {
            orientationUtils3.setEnable(false);
        }
        ((ActivityVideoPlayLayoutBinding) this.binding).player.onPlayerPause();
        this.status = this.videoBean.getReasonType();
        ((ActivityVideoPlayLayoutBinding) this.binding).setStatus(Integer.valueOf(this.status));
    }

    private void addVideoWatchTimes(int i) {
        if (this.videoBean != null) {
            UserInfo userInfo2 = SpUtils.getInstance().getUserInfo();
            userInfo2.setWatched(userInfo2.getWatched() + 1);
            SpUtils.getInstance().setUserInfo(userInfo2);
            this.model.addStatisticsTimes(this.videoBean.getVideoType() + 1, i, this.videoId);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void collectState(int i, String str) {
        ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.setVisibility(0);
        ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.setText(str);
        if (i == 1) {
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.setTextColor(getResources().getColor(R.color.white));
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.setBackgroundResource(R.drawable.shape_bg_collect_state);
        } else {
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.setTextColor(getResources().getColor(R.color.mainColor));
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.setBackgroundResource(R.drawable.shape_bg_collect_state_one);
        }
        ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvCollectState.postDelayed(new Runnable() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.RunnableC293314 */

            public void run() {
                VideoPlayActivity.this.runOnUiThread(new Runnable() {
                    /* class com.grass.p019lv.activity.VideoPlayActivity.RunnableC293314.RunnableC29341 */

                    public void run() {
                        ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).detailVideo.tvCollectState.setVisibility(8);
                    }
                });
            }
        }, 1500);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void playerSubsequentProcessing() {
        if (this.isFirst) {
            this.isFirst = false;
        } else {
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.tvDownload.setText("下載");
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.ivDownload.setImageResource(0);
            ((ActivityVideoPlayLayoutBinding) this.binding).detailVideo.ivDownload.setImageResource(R.drawable.ic_video_download_new);
        }
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null) {
            if (videoBean2.getCoverImg() != null && this.videoBean.getCoverImg().size() > 0) {
                VideoPlayer videoPlayer = ((ActivityVideoPlayLayoutBinding) this.binding).player;
                videoPlayer.loadCoverImage(SpUtils.getInstance().getString("domain") + this.videoBean.getCoverImg().get(0));
            }
            this.videoUrl = UrlManager.getInsatance().playBaseFull2(this.videoBean.getVideoId());
            this.m3u8Model.getM3u8(this.videoBean.getPlayPath(), 1);
        }
    }

    /* access modifiers changed from: package-private */
    public void setAd() {
        final AdInfoBean play = AdUtils.getInstance().getPlay();
        if (play == null) {
            ((ActivityVideoPlayLayoutBinding) this.binding).rlAd.setVisibility(8);
            ((ActivityVideoPlayLayoutBinding) this.binding).ivAd.setVisibility(8);
            ((ActivityVideoPlayLayoutBinding) this.binding).tvAd.setVisibility(8);
            return;
        }
        ViewGroup.LayoutParams layoutParams = ((ActivityVideoPlayLayoutBinding) this.binding).rlAd.getLayoutParams();
        layoutParams.height = ((UiUtils.getWindowWidth() - UiUtils.dp2px(20)) * 120) / 400;
        ((ActivityVideoPlayLayoutBinding) this.binding).rlAd.setLayoutParams(layoutParams);
        ((ActivityVideoPlayLayoutBinding) this.binding).rlAd.setVisibility(0);
        ((ActivityVideoPlayLayoutBinding) this.binding).ivAd.setVisibility(0);
        ((ActivityVideoPlayLayoutBinding) this.binding).tvAd.setVisibility(0);
        GlideUtils.loadCropRadius(SpUtils.getInstance().getString("domain") + play.getAdImage(), 4, ((ActivityVideoPlayLayoutBinding) this.binding).ivAd);
        ((ActivityVideoPlayLayoutBinding) this.binding).ivAd.setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.View$OnClickListenerC293515 */

            public void onClick(View view) {
                if (play.getJumpType() == 2) {
                    try {
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        intent.setData(Uri.parse(play.getAdJump()));
                        VideoPlayActivity.this.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    if (VideoPlayActivity.this.appLink == null) {
                        VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
                        videoPlayActivity.appLink = new APPLink(videoPlayActivity.getActivity());
                    }
                    VideoPlayActivity.this.appLink.urlLink(play.getAdJump());
                }
                Intent intent2 = new Intent(VideoPlayActivity.this.getActivity(), AdClickService.class);
                intent2.putExtra("adId", play.getAdId());
                VideoPlayActivity.this.getActivity().startService(intent2);
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void canVipVideo(CanWatchVipEvent canWatchVipEvent) {
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null && videoBean2.getVideoType() != 2) {
            this.status = 0;
            ((ActivityVideoPlayLayoutBinding) this.binding).setStatus(Integer.valueOf(this.status));
            this.videoBean.setCanWatch(true);
            this.videoUrl = UrlManager.getInsatance().playBaseFull2(this.videoBean.getVideoId());
            if (!TextUtils.isEmpty(this.videoBean.getPlayPath())) {
                this.m3u8Model.getM3u8(this.videoBean.getPlayPath(), 1);
            }
            this.userInfo.setFreeWatches(-1);
            ((ActivityVideoPlayLayoutBinding) this.binding).setUserInfo(this.userInfo);
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.fragment.app.FragmentActivity
    public void onPause() {
        ((ActivityVideoPlayLayoutBinding) this.binding).player.onVideoPause();
        super.onPause();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.fragment.app.FragmentActivity
    public void onResume() {
        if (((ActivityVideoPlayLayoutBinding) this.binding).getStatus().intValue() == 0) {
            ((ActivityVideoPlayLayoutBinding) this.binding).player.onVideoResume();
        }
        this.userAccount = SpUtils.getInstance().getUserAccount();
        CompositeDisposable compositeDisposable2 = new CompositeDisposable();
        this.compositeDisposable = compositeDisposable2;
        compositeDisposable2.add(Observable.create(new ObservableOnSubscribe<String>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C293817 */

            @Override // p023io.reactivex.ObservableOnSubscribe
            public void subscribe(ObservableEmitter<String> observableEmitter) {
                observableEmitter.onNext(DataCacheUtils.loadListCache(VideoPlayActivity.this));
            }
        }).subscribeOn(Schedulers.m1118io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
            /* class com.grass.p019lv.activity.VideoPlayActivity.C293616 */

            public void accept(String str) throws Exception {
                if (!TextUtils.isEmpty(str)) {
                    VideoPlayActivity.this.downLoadTask.clear();
                    VideoPlayActivity.this.downLoadTask.addAll((List) VideoPlayActivity.this.mGson.fromJson(str, new TypeToken<List<DownloadVideoBean>>() {
                        /* class com.grass.p019lv.activity.VideoPlayActivity.C293616.C29371 */
                    }.getType()));
                    M3U8Task isVideoDownload = VideoPlayActivity.this.isVideoDownload();
                    if (isVideoDownload != null) {
                        if (M3U8Downloader.getInstance().checkM3U8IsExist(isVideoDownload.getUrl())) {
                            isVideoDownload.setState(3);
                        } else {
                            isVideoDownload.setState(5);
                        }
                        if (M3U8Downloader.getInstance().isCurrentTask(isVideoDownload.getUrl())) {
                            isVideoDownload.setState(2);
                        }
                        VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
                        videoPlayActivity.setProgressText(((ActivityVideoPlayLayoutBinding) videoPlayActivity.binding).detailVideo.tvDownload, ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).detailVideo.ivDownload, isVideoDownload);
                    }
                }
                if (VideoPlayActivity.this.compositeDisposable != null) {
                    VideoPlayActivity.this.compositeDisposable.dispose();
                }
            }
        }));
        super.onResume();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity
    public void onStop() {
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null && videoBean2.isCanWatch()) {
            this.model.insertHistory(this.videoBean, ((ActivityVideoPlayLayoutBinding) this.binding).player.getProgress());
        }
        super.onStop();
    }

    public static void setViewHeight(View view, int i) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.height = i;
        view.setLayoutParams(layoutParams);
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        VideoPlayerModel videoPlayerModel = this.model;
        if (videoPlayerModel != null) {
            videoPlayerModel.cancelHttp();
        }
        if (!(this.binding == null || ((ActivityVideoPlayLayoutBinding) this.binding).player == null)) {
            ((ActivityVideoPlayLayoutBinding) this.binding).player.release();
        }
        OrientationUtils orientationUtils2 = this.orientationUtils;
        if (orientationUtils2 != null) {
            orientationUtils2.releaseListener();
        }
        super.onDestroy();
    }

    /* renamed from: com.grass.lv.activity.VideoPlayActivity$OnClick */
    public class OnClick {
        public void emptyClick() {
        }

        public OnClick() {
        }

        public void btnBack() {
            VideoPlayActivity.this.finish();
        }

        public void buyVip() {
            if (!VideoPlayActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.VIP_CENTER_ACTIVITY).navigation();
            }
        }

        public void buyVideo() {
            if (VideoPlayActivity.this.isOnClick() || VideoPlayActivity.this.videoBean == null) {
                return;
            }
            if (VideoPlayActivity.this.userAccount.getGold() < VideoPlayActivity.this.videoBean.getPrice()) {
                ToastUtils.getInstance().showSigh("金幣不足，請充值");
                ARouter.getInstance().build(Constance.VIP_CENTER_ACTIVITY).withInt("type", 1).navigation();
                return;
            }
            VideoPlayActivity.this.model.buyOrLeaseVideo(VideoPlayActivity.this.videoBean.getVideoId(), 1, false, VideoPlayActivity.this);
        }

        public void leaseVideo() {
            if (VideoPlayActivity.this.isOnClick() || VideoPlayActivity.this.videoBean == null) {
                return;
            }
            if (VideoPlayActivity.this.userAccount.getGold() < VideoPlayActivity.this.videoBean.getLeasePrice()) {
                ToastUtils.getInstance().showSigh("金幣不足，請充值");
                ARouter.getInstance().build(Constance.VIP_CENTER_ACTIVITY).withInt("type", 1).navigation();
                return;
            }
            VideoPlayActivity.this.model.buyOrLeaseVideo(VideoPlayActivity.this.videoBean.getVideoId(), 3, false, VideoPlayActivity.this);
        }

        public void collectForVideo() {
            if (!VideoPlayActivity.this.isOnClick() && VideoPlayActivity.this.videoBean != null) {
                if (VideoPlayActivity.this.videoBean.isLike()) {
                    VideoPlayActivity.this.collectState(0, "取消收藏");
                    if (VideoPlayActivity.this.videoBean.getFakeLikes() >= 1) {
                        VideoPlayActivity.this.videoBean.setFakeLikes(VideoPlayActivity.this.videoBean.getFakeLikes() - 1);
                    }
                    VideoPlayActivity.this.model.unLikeVideo(VideoPlayActivity.this.videoBean.getVideoId());
                } else {
                    VideoPlayActivity.this.collectState(1, "已收藏，可在個人中心快速找到");
                    VideoPlayActivity.this.videoBean.setFakeLikes(VideoPlayActivity.this.videoBean.getFakeLikes() + 1);
                    VideoPlayActivity.this.model.likeVideo(VideoPlayActivity.this.videoBean.getVideoId());
                }
                VideoPlayActivity.this.videoBean.setLike(true ^ VideoPlayActivity.this.videoBean.isLike());
                ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).setVideoBean(VideoPlayActivity.this.videoBean);
                EventBus.getDefault().post(new LikeVideoEvent(VideoPlayActivity.this.videoBean.isLike(), VideoPlayActivity.this.videoBean.getVideoId()));
            }
        }

        public void scoreForVideo() {
            if (VideoPlayActivity.this.videoBean == null || !VideoPlayActivity.this.videoBean.isScored()) {
                VideoPlayActivity.this.ratingBar.show();
            } else {
                ToastUtils.getInstance().showSigh("妳已經評過分了");
            }
        }

        public void shareForVideo() {
            ARouter.getInstance().build(Constance.SHARE_ACTIVITY).withInt(Key.VIDEO_ID, VideoPlayActivity.this.videoId).navigation();
        }

        public void relatedWorksMore() {
            List<ContentBean> contentList;
            if (!VideoPlayActivity.this.isOnClick() && VideoPlayActivity.this.videoBean != null && (contentList = VideoPlayActivity.this.videoBean.getContentList()) != null && contentList.size() > 0) {
                ARouter.getInstance().build(Constance.STAR_INFO_ACTIVITY).withInt("type", contentList.get(0).getContentId()).withString(Key.TXT, "返回").navigation();
            }
        }

        public int isHaveContent(VideoBean videoBean) {
            return (videoBean == null || videoBean.getContentList() == null || videoBean.getContentList().size() <= 0) ? 0 : 1;
        }

        public void downLoadVideo() {
            if (!VideoPlayActivity.this.isOnClick() && NetUtil.isNetworkAvailable()) {
                M3U8Task isVideoDownload = VideoPlayActivity.this.isVideoDownload();
                if (isVideoDownload == null) {
                    VideoPlayActivity.this.model.getDownLoadVideoNum();
                    return;
                }
                String url = isVideoDownload.getUrl();
                if (!M3U8Downloader.getInstance().checkM3U8IsExist(url)) {
                    M3U8Downloader.getInstance().download(url);
                    VideoPlayActivity.this.getActivity().startService(new Intent(VideoPlayActivity.this.getActivity(), DownloadVideoService.class));
                }
            }
        }
    }

    public void downLoad(int i) {
        VideoBean videoBean2 = this.videoBean;
        if (videoBean2 != null) {
            if (i == 0 && !videoBean2.isCanWatch() && this.videoBean.getVideoType() == 2) {
                new DownLoadVideoDialog(this, 2, "").show();
            } else if (i == 0 && !this.videoBean.isCanWatch() && this.videoBean.getVideoType() == 1) {
                new DownLoadVideoDialog(this, 3, "").show();
            } else if (i == 0) {
                new DownLoadVideoDialog(this, 1, "你的下載次數已用完").show();
            } else {
                M3U8Task m3U8Task = new M3U8Task(this.videoUrl);
                ArrayList<DownloadVideoBean> arrayList = this.downLoadTask;
                if (arrayList == null || arrayList.size() <= 0) {
                    this.downLoadTask.add(0, new DownloadVideoBean(this.videoBean, m3U8Task));
                } else if (this.downLoadTask.size() > 0) {
                    if (m3U8Task.getUrl().equals(this.downLoadTask.get(0).getM3U8Task().getUrl())) {
                        this.downLoadTask.get(0).setM3U8Task(m3U8Task);
                    } else {
                        this.downLoadTask.add(0, new DownloadVideoBean(this.videoBean, m3U8Task));
                    }
                }
                new DownLoadVideoDialog(this, 0, "").show();
                DataCacheUtils.saveListCache(this, this.mGson.toJson(this.downLoadTask));
                M3U8Downloader.getInstance().download(this.videoUrl);
                startService(new Intent(this, DownloadVideoService.class));
            }
        }
    }

    public M3U8Task isVideoDownload() {
        ArrayList<DownloadVideoBean> arrayList = this.downLoadTask;
        if (arrayList != null && arrayList.size() > 0) {
            for (int i = 0; i < this.downLoadTask.size(); i++) {
                if (this.videoUrl.equals(this.downLoadTask.get(i).getM3U8Task().getUrl())) {
                    return this.downLoadTask.get(i).getM3U8Task();
                }
            }
        }
        return null;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setProgressText(TextView textView, ImageView imageView, M3U8Task m3U8Task) {
        imageView.setImageResource(0);
        switch (m3U8Task.getState()) {
            case -1:
                textView.setText("等待中");
                imageView.setImageResource(R.drawable.ic_download_downloading_new);
                return;
            case 0:
            default:
                textView.setText("暫停中");
                imageView.setImageResource(R.drawable.ic_download_downloading_new);
                return;
            case 1:
                imageView.setImageResource(R.drawable.ic_download_downloading_new);
                return;
            case 2:
                textView.setText("(" + String.format("%.2f", Float.valueOf(m3U8Task.getProgress() * 100.0f)) + "%)");
                imageView.setImageResource(R.drawable.ic_download_downloading_new);
                return;
            case 3:
                textView.setText("");
                imageView.setImageResource(R.drawable.ic_download_success_new);
                return;
            case 4:
                return;
            case 5:
                textView.setText("暫停中");
                imageView.setImageResource(R.drawable.ic_download_downloading_new);
                return;
            case 6:
                textView.setText("存儲空間不足");
                imageView.setImageResource(R.drawable.ic_download_downloading_new);
                return;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void updateText(final M3U8Task m3U8Task) {
        if (this.videoUrl.equals(m3U8Task.getUrl())) {
            runOnUiThread(new Runnable() {
                /* class com.grass.p019lv.activity.VideoPlayActivity.RunnableC294119 */

                public void run() {
                    VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
                    videoPlayActivity.setProgressText(((ActivityVideoPlayLayoutBinding) videoPlayActivity.binding).detailVideo.tvDownload, ((ActivityVideoPlayLayoutBinding) VideoPlayActivity.this.binding).detailVideo.ivDownload, m3U8Task);
                }
            });
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getVideoPath(M3u8Event m3u8Event) {
        if (1 == m3u8Event.getType()) {
            ((ActivityVideoPlayLayoutBinding) this.binding).player.setUp(m3u8Event.getVideoPath(), false, "");
            ((ActivityVideoPlayLayoutBinding) this.binding).player.onPrepared();
            ((ActivityVideoPlayLayoutBinding) this.binding).player.startPlayLogic();
        }
    }
}
